package org.apache.ocean.name;

import java.util.Date;
import org.jdom.Element;
import java.net.URL;
import org.apache.ocean.TransactionID;
import org.apache.ocean.CElement;
import org.apache.ocean.XMLUtil;
import org.apache.ocean.database.DB;
import org.apache.ocean.CLong;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.ocean.OceanXML;
/**
 *
 * @author jasonr
 */
public class Node implements CElement {
  @DB(primarykey=true)
  public String id;
  @DB(index=true)
  public String assignedCellID;
  public String assignedStatus; // master,slave,offline,corrupted
  public String reportedCellID;
  public String reportedStatus; // master,slave,corrupted
  public Date reportedStatusSinceDate;
  public String reportedMasterID;
  public Date reportedMasterIDSinceDate;
  public Date reportDate;
  public TransactionID highestCellTransactionIDDatabase;
  public TransactionID highestCellTransactionIDIndex;
  //public TransactionID lowestTransactionIDLogAvg;
  //public TransactionID highestTransactionIDIndexAvg;
  //public TransactionID lowestTransactionIDIndexAvg;
  public URL url;
  public Date dateCreated;
  public Date dateModified;
  public CLong totalSize;
  public CLong totalIndicesSize;
  public CLong totalTransactionLogsSize;
  public TransactionID replicationID;
  
  public Node() {}
  
  public Node(Element element) throws Exception {
    XMLUtil.reflectToObject(this, element);
  }
  
  public static class Transform implements OceanXML.Transform {
    public Object call(Element element) throws Exception {
      return new Node(element);
    }
  }
  
  public String toString() {
    return ReflectionToStringBuilder.toString(this);
  }
  
  public Element toElement() throws Exception {
    return XMLUtil.reflectToElement("node", this);
  }
}
